package com.yzf.demo.demo.Thread;

import java.util.concurrent.*;

/**
 * Created by 于占峰 on 2020/3/28/028.
 * 实现Callable<?>接口 指定需要的返回值参数
 */
public class CallableDemo implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("当前线程:" + Thread.currentThread().getName());
        return "Hell Callable";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //构建一个线程池
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        //调用submit 传入类 返回 Future
        Future<String> future = executorService.submit(new CallableDemo());
        //future.get() 拿到线程的返回值 future.get()是一个阻塞方法 只有线程返回结果后才会执行
        System.out.println(future.get());
    }
}
